﻿Imports DevComponents.DotNetBar.SuperGrid
Imports DevComponents.DotNetBar.SuperGrid.Style
Public Class SOFTWAREINGROUP
    Dim connect As CONDB = CONDB.NewConnection()
    Dim selectPrgGroupRow As Integer = -1

    Private Sub SOFTWAREINGROUP_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        queryPrgGroupGrid()
    End Sub

    Public Sub queryPrgGroupGrid()
        Dim userGroupGrid As DataTable = connect.GetTable("SELECT gprgid AS 'รหัสกลุ่มซอฟต์แวร์', gprgname AS 'ชื่อกลุ่มซอฟต์แวร์', `status` AS 'สถานะการเปิดใช้งาน' FROM masgrpprg")
        groupSoftwareGrid.PrimaryGrid.DataSource = userGroupGrid
    End Sub

    Private Sub groupSoftwareGrid_CellClick(sender As Object, e As GridCellClickEventArgs) Handles groupSoftwareGrid.CellClick
        If e.MouseEventArgs.Button = Windows.Forms.MouseButtons.Right Then
            selectPrgGroupRow = e.GridCell.RowIndex
        End If
    End Sub

    Private Sub giveSoftwareAndPolicy_Click(sender As Object, e As EventArgs) Handles giveSoftwareAndPolicy.Click
        Dim prgGroupid As String = CType(groupSoftwareGrid.PrimaryGrid.Rows(selectPrgGroupRow), GridRow).Cells("รหัสกลุ่มซอฟต์แวร์").Value
        Dim prgGroupName As String = CType(groupSoftwareGrid.PrimaryGrid.Rows(selectPrgGroupRow), GridRow).Cells("ชื่อกลุ่มซอฟต์แวร์").Value

        Dim CMSPHERE As New SOFTWAREINGROUPPOLICY(prgGroupid, prgGroupName)
        Dim resultForm As DialogResult = CMSPHERE.ShowDialog
    End Sub

    Private Sub editNameOfSoftwareGroup_Click(sender As Object, e As EventArgs) Handles editNameOfSoftwareGroup.Click
        Dim prgGroupid As String = CType(groupSoftwareGrid.PrimaryGrid.Rows(selectPrgGroupRow), GridRow).Cells("รหัสกลุ่มซอฟต์แวร์").Value
        Dim prgGroupName As String = CType(groupSoftwareGrid.PrimaryGrid.Rows(selectPrgGroupRow), GridRow).Cells("ชื่อกลุ่มซอฟต์แวร์").Value
        Dim prgGroupStatus As String = CType(groupSoftwareGrid.PrimaryGrid.Rows(selectPrgGroupRow), GridRow).Cells("สถานะการเปิดใช้งาน").Value

        Dim CMSPHERE As New SOFTWAREGROUPEDIT(prgGroupid, prgGroupName, prgGroupStatus)
        Dim resultForm As DialogResult = CMSPHERE.ShowDialog

        If resultForm = Windows.Forms.DialogResult.OK Then
            queryPrgGroupGrid()
        End If
    End Sub

    Private Sub newSoftwareGroupBtn_Click(sender As Object, e As EventArgs) Handles newSoftwareGroupBtn.Click
        Dim newFOrm As New NEWGROUPSOFTWARE()
        Dim resultForm As DialogResult = newFOrm.ShowDialog()

        If resultForm = Windows.Forms.DialogResult.OK Then
            queryPrgGroupGrid()
        End If
    End Sub
End Class